//
//  UIColor+Extension.swift
//  weibo
//
//  Created by 李江波 on 16/10/7.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

import UIKit

extension  UIColor{

    
    /// 16进制得到颜色
    ///
    /// - parameter rgbValue: 16进制
    /// - parameter alpha:    透明度
    ///
    /// - returns:
    convenience init(rgbValue: Int, alpha: Float = 1.0) {
        
//        #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
        
        self.init(red:   CGFloat( (rgbValue & 0xFF0000) >> 16 ) / 255.0,
                  green: CGFloat( (rgbValue & 0x00FF00) >> 8 ) / 255.0,
                  blue:  CGFloat( (rgbValue & 0x0000FF) >> 0 ) / 255.0,
                  alpha: CGFloat(alpha))
    
    }
    
}


extension UIColor{
    
    
    
    /// 随机颜色
    ///
    /// - parameter alpha: 透明度
    ///
    /// - returns:
    convenience init(alpha: CGFloat ) {
       
        let red = CGFloat(arc4random_uniform(255)) / 255.0
            let green = CGFloat(arc4random_uniform(255)) / 255.0
                let blue = CGFloat(arc4random_uniform(255)) / 255.0
    
        self.init(red: red, green: green, blue: blue,alpha : alpha)
    
    }
}


